using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Serialization;
using ICP_MS.Plugin.Tune.Properties;
using ZedGraph;

namespace ICP_MS.Plugin.Tune;

public class FormScan_Ncs : Form
{
	public List<MassData> massDatas = new List<MassData>();

	private GraphPane graphPane = null;

	private volatile bool stopScan = true;

	private int sweepIndex = 0;

	private int massIndex = 0;

	private const double a = 0.237;

	private const double q = 0.706;

	private const double pai = 3.1415926;

	private const double n = 2.0;

	private const double z = 1.0;

	private const double r0 = 0.005325;

	private const double sm = 1.66053873;

	private const double e = 1.0;

	private const double se = 1.602176462;

	private const double coe = 100000000.0;

	private double newDCPos = double.NaN;

	private double oldDCPos = double.NaN;

	private double deltaDC = 0.5;

	private AutoResetEvent scanEvent = new AutoResetEvent(initialState: false);

	private IContainer components = null;

	private ToolStrip toolStrip1;

	private ToolStripButton tsbtnScan;

	private ToolStripButton tsbtnStop;

	private ToolStripSeparator toolStripSeparator1;

	private ToolStripSeparator toolStripSeparator2;

	private ToolStripButton tsbtnImport;

	private ToolStripButton tsbtnExport;

	private SplitContainer splitContainer1;

	private DataGridView dgvMass;

	private ZedGraphControl graphSpectrum;

	private ToolStripSeparator toolStripSeparator3;

	private ToolStripComboBox tscbSpectrum;

	private DataGridViewTextBoxColumn dataGridViewTextBoxColumn1;

	private DataGridViewTextBoxColumn dataGridViewTextBoxColumn2;

	private DataGridViewTextBoxColumn dataGridViewTextBoxColumn3;

	private DataGridViewTextBoxColumn dataGridViewTextBoxColumn4;

	private DataGridViewTextBoxColumn dataGridViewTextBoxColumn5;

	private DataGridViewTextBoxColumn dataGridViewTextBoxColumn6;

	private DataGridViewTextBoxColumn dataGridViewTextBoxColumn7;

	private DataGridViewTextBoxColumn dataGridViewTextBoxColumn8;

	private ToolStripButton tsbtnSave;

	private ToolStripSeparator toolStripSeparator4;

	private ToolStripSeparator toolStripSeparator5;

	private DataGridViewTextBoxColumn ColSymbol;

	private DataGridViewTextBoxColumn colStart;

	private DataGridViewTextBoxColumn colEnd;

	private DataGridViewTextBoxColumn colChannels;

	private DataGridViewTextBoxColumn colSweeps;

	private DataGridViewTextBoxColumn colkRf;

	private DataGridViewTextBoxColumn colbRF;

	private DataGridViewTextBoxColumn colkDC;

	private DataGridViewTextBoxColumn colbDC;

	private ToolStripButton toolStripButton1;

	public FormScan_Ncs()
	{
		InitializeComponent();
		graphPane = graphSpectrum.GraphPane;
	}

	public void StopRun()
	{
	}

	private void BindMass()
	{
		dgvMass.AutoGenerateColumns = false;
		massDatas.Sort((MassData m1, MassData m2) => m1.start.CompareTo(m2.start));
		colStart.SortMode = DataGridViewColumnSortMode.Automatic;
		if (dgvMass.DataSource == null)
		{
			dgvMass.DataSource = new BindingList<MassData>(massDatas);
			return;
		}
		BindingContext[dgvMass.DataSource].SuspendBinding();
		dgvMass.DataSource = null;
		dgvMass.DataSource = new BindingList<MassData>(massDatas);
		BindingContext[dgvMass.DataSource].ResumeBinding();
	}

	private void InitSpectrum()
	{
		graphPane.CurveList.Clear();
		int index = tscbSpectrum.SelectedIndex;
		for (int i = 0; i < massDatas.Count; i++)
		{
			LineItem item1 = graphPane.AddCurve("", new PointPairList(), Color.Blue, SymbolType.None);
			item1.Line.Width = 1f;
			LineItem item2 = graphPane.AddCurve("", new PointPairList(), Color.Red, SymbolType.None);
			item2.Line.Width = 1f;
			switch (index)
			{
			case 0:
				item2.IsVisible = false;
				break;
			case 1:
				item1.IsVisible = false;
				break;
			}
		}
	}

	private void FormScan_Ncs_Load(object sender, EventArgs e)
	{
		base.WindowState = FormWindowState.Maximized;
		BindMass();
		graphPane = graphSpectrum.GraphPane;
		graphPane.Title.Text = "Spectrum";
		graphPane.XAxis.Title.Text = "m/z";
		graphPane.YAxis.Title.Text = "ICPS";
		tscbSpectrum.SelectedIndex = 1;
		Detector.analogReceive += Scan_analogRecieve;
		Detector.pulseReceive += Scan_pulseReceive;
		Detector.finishReceive += Scan_massFinishReceive;
		Detector.ExperimentStateChanged += Detector_ExperimentStateChanged;
		ApplyResources();
	}

	private void Detector_errorReceive(object sender, ErrorMsgEventArgs e)
	{
		LensManager.x2lens.Etp = 0.0;
		LensManager.Instance.SetEtp();
		StopScan();
		MessageBox.Show("质量数为" + e.X + "元素浓度过高请检查，已停止测试！", "警告-倍增器保护");
	}

	private void Detector_ExperimentStateChanged(object sender, ExperimentStateArgs e)
	{
		if (e.State == 4)
		{
			StopScan();
		}
	}

	private void ApplyResources()
	{
		Text = Lang.Txt("FormScanNCS.Title.Text");
		tsbtnExport.Text = Lang.Txt("FormScanNCS.Save.Text");
		tsbtnImport.Text = Lang.Txt("FormScanNCS.Open.Text");
		tsbtnSave.Text = Lang.Txt("FormScanNCS.SaveSpectrum.Text");
		tsbtnStop.Text = Lang.Txt("FormScanNCS.End.Text");
		colChannels.HeaderText = Lang.Txt("FormScanNCS.Columns.Channel.Text");
		colEnd.HeaderText = Lang.Txt("FormScanNCS.Columns.End.Text");
		colStart.HeaderText = Lang.Txt("FormScanNCS.Columns.Start.Text");
		colSweeps.HeaderText = Lang.Txt("FormScanNCS.Columns.Sweeps.Text");
		tscbSpectrum.Items[0] = Lang.Txt("FormInstrumentTune.Mode.Analog.Text");
		tscbSpectrum.Items[1] = Lang.Txt("FormInstrumentTune.Mode.PC.Text");
		tscbSpectrum.Items[2] = Lang.Txt("FormInstrumentTune.Mode.All.Text");
		tsbtnScan.Text = Lang.Txt("ADDTune.Scan.Text");
		toolStripButton1.Text = Lang.Txt("ADDTune.Scan.AutomaticCorrection");
		ColSymbol.HeaderText = Lang.Txt("ADDTune.Scan.Element");
		tsbtnImport.ToolTipText = Lang.Txt("ADDTune.Scan.ImportScanData");
		tsbtnExport.ToolTipText = Lang.Txt("ADDTune.Scan.SaveScanData");
		tsbtnSave.ToolTipText = Lang.Txt("ADDTune.Scan.SaveSpectralData");
	}

	private void tsbtnSpectrum_SelectedIndexChanged(object sender, EventArgs e)
	{
		int selectIndex = tscbSpectrum.SelectedIndex;
		if (graphPane.CurveList.Count > 0)
		{
			for (int i = 0; i < graphPane.CurveList.Count; i++)
			{
				if (selectIndex == 2)
				{
					graphPane.CurveList[i].IsVisible = true;
				}
				else
				{
					graphPane.CurveList[i].IsVisible = i % 2 == selectIndex;
				}
			}
		}
		graphSpectrum.Refresh();
	}

	private void tsbtnScan_Click(object sender, EventArgs e)
	{
		if (Detector.Instance.ExperimentState != -1)
		{
			if (Detector.Instance.ExperimentState == 4)
			{
				MessageBox.Show(Lang.Txt("ADDTune.TipsText1.Text"), Lang.Txt("AddFormIgnite.Warn"));
				return;
			}
			if (MessageBox.Show(Lang.Txt("ADDTune.TipsText2.Text"), Lang.Txt("AddFormIgnite.Warn"), MessageBoxButtons.YesNo) != DialogResult.Yes)
			{
				return;
			}
			Detector.Instance.ExperimentStateChange(Detector.Instance.ExperimentState);
		}
		if (!InitScan())
		{
			MessageBox.Show(Lang.Txt("FormScanNCS.MessageBox.ErrorSet.Text"));
			return;
		}
		EnableScan(enable: false);
		sweepIndex = 0;
		massIndex = 0;
		stopScan = false;
		Task.Factory.StartNew(ThreadRefresh);
		Task.Factory.StartNew(StartScan);
		Detector.Instance.ExperimentState = 4;
	}

	private void tsbtnStop_Click(object sender, EventArgs e)
	{
		StopScan();
		Detector.Instance.ExperimentState = -1;
	}

	private bool InitScan()
	{
		foreach (MassData ms in massDatas)
		{
			if (ms.start >= ms.end)
			{
				return false;
			}
		}
		InitSpectrum();
		return true;
	}

	private double CalculateDC(double mass, double f)
	{
		return mass * 1.66053873 / 160217646.20000002 * (0.237 * (6.2831852 * f) * (6.2831852 * f) * 0.005325 * 0.005325 / 8.0);
	}

	private double CalculateRF(double mass, double f)
	{
		return mass * 1.66053873 / 160217646.20000002 * (0.706 * (6.2831852 * f) * (6.2831852 * f) * 0.005325 * 0.005325 / 4.0);
	}

	public double CalculateCoeDC(double U, double f)
	{
		double buf = 1.0364268664433792E-08 * (0.237 * (6.2831852 * f) * (6.2831852 * f) * 0.005325 * 0.005325 / 8.0);
		return U / buf;
	}

	public double CalculateCoeRF(double V, double f)
	{
		double buf = 1.0364268664433792E-08 * (0.706 * (6.2831852 * f) * (6.2831852 * f) * 0.005325 * 0.005325 / 8.0);
		return V / buf;
	}

	private void StartScan()
	{
		massIndex = 0;
		while (massIndex < massDatas.Count && !stopScan)
		{
			Thread.Sleep(5);
			MassData ms = massDatas[massIndex];
			SetCalibrationFactor(ms);
			List<double> mass = SetMassAxis(ms);
			List<int> res = new List<int>();
			for (int i = 0; i < mass.Count; i++)
			{
				res.Add(1);
			}
			sweepIndex = 0;
			while (sweepIndex < ms.sweeps && !stopScan)
			{
				scanEvent.Reset();
				Detector.AcquistionState = 0;
				if (sweepIndex == 0)
				{
					Detector.Instance.SetMassAxis(mass.ToArray());
				}
				Detector.TimerInit();
				Detector.Instance.SendHopDatas(mass.ToArray(), res.ToArray(), true, true);
				if (!scanEvent.WaitOne(120000))
				{
					Log.InsertLog(Lang.Txt("FormScanNCS.LogContent1.Text"), Lang.Txt("FormExperLog.Text2"), Lang.Txt("FormExperLog.Text3"), (Severity)3);
				}
				else if (Detector.AcquistionState == 2)
				{
					MessageBox.Show(Lang.Txt("FormScanNCS.TipsText1.Text"), Lang.Txt("AddFormIgnite.Warn"));
					break;
				}
				Detector.TimerDeinit();
				sweepIndex++;
			}
			if (Detector.AcquistionState == 2)
			{
				break;
			}
			massIndex++;
		}
		StopScan();
	}

	private void StopScan()
	{
		scanEvent.Set();
		stopScan = true;
		Detector.Instance.Stop();
		EnableScan(enable: true);
		Detector.Instance.ExperimentState = -1;
		Detector.TimerDeinit();
	}

	private List<double> SetMassAxis(MassData ms)
	{
		float begin = ms.start;
		float end = ms.end;
		int channels = ms.channels;
		List<double> mass = new List<double>();
		for (float i = begin; i <= end; i += 1f / (float)channels)
		{
			mass.Add(i);
		}
		return mass;
	}

	private void SetBaseCalibrationFactor(MassData ms)
	{
	}

	private void SetCalibrationFactor(MassData ms)
	{
		Detector.Instance.SetCalibrationFactor((double)ms.kRF, (double)ms.bRF, (double)ms.kDC, (double)ms.bDC);
	}

	private void dgvMass_DataError(object sender, DataGridViewDataErrorEventArgs e)
	{
		MessageBox.Show(Lang.Txt("FormScanNCS.MessageBox.ErrorFormat.Text"));
	}

	private void EnableScan(bool enable)
	{
		Invoke((EventHandler)delegate
		{
			tsbtnScan.Enabled = enable;
			tsbtnImport.Enabled = enable;
			tsbtnExport.Enabled = enable;
			dgvMass.Enabled = enable;
			RefreshGraph();
		});
	}

	private void Scan_analogRecieve(object sender, PointEventArgs e)
	{
		if (stopScan)
		{
			return;
		}
		int index = e.Index;
		double x = e.X;
		double y = e.Y;
		try
		{
			if (sweepIndex == 0)
			{
				graphPane.CurveList[massIndex * 2].AddPoint(x, y);
			}
			else
			{
				graphPane.CurveList[massIndex * 2].Points[index].Y += y;
			}
		}
		catch (Exception ex)
		{
			Log.InsertLog("Ncs scan", "Analog receive error", ex.Message, (Severity)3);
		}
	}

	private void Scan_pulseReceive(object sender, PointEventArgs e)
	{
		if (stopScan)
		{
			return;
		}
		int index = e.Index;
		double x = e.X;
		double y = e.Y;
		try
		{
			if (sweepIndex == 0)
			{
				graphPane.CurveList[massIndex * 2 + 1].AddPoint(x, y);
			}
			else
			{
				graphPane.CurveList[massIndex * 2 + 1].Points[index].Y += y;
			}
		}
		catch (Exception ex)
		{
			Log.InsertLog("Ncs scan", "Pulse data receive error", ex.Message, (Severity)3);
			Console.WriteLine("PC:" + ex.Message);
		}
	}

	private void Scan_massFinishReceive(object sender, EventArgs e)
	{
		if (!stopScan)
		{
			scanEvent.Set();
		}
	}

	private void tsbtnImport_Click(object sender, EventArgs e)
	{
		OpenFileDialog dlg = new OpenFileDialog();
		dlg.Filter = "Xml files(*.xml)|*.xml";
		if (dlg.ShowDialog() != DialogResult.OK)
		{
			return;
		}
		using FileStream fs = new FileStream(dlg.FileName, FileMode.Open, FileAccess.Read);
		try
		{
			XmlSerializer serializer = new XmlSerializer(typeof(List<MassData>));
			if (serializer.Deserialize(fs) is List<MassData> tmp)
			{
				massDatas.Clear();
				massDatas.AddRange(tmp.ToArray());
				BindMass();
			}
		}
		catch
		{
			MessageBox.Show(Lang.Txt("FormScanNCS.MessageBox.FileNotOK.Text"));
		}
	}

	private void tsbtnExport_Click(object sender, EventArgs e)
	{
		SaveFileDialog dlg = new SaveFileDialog();
		dlg.Filter = "Xml files(*.xml)|*.xml";
		dlg.FileName = DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss") + ".xml";
		if (dlg.ShowDialog() == DialogResult.OK)
		{
			using (FileStream fs = new FileStream(dlg.FileName, FileMode.Create, FileAccess.Write))
			{
				XmlSerializer serializer = new XmlSerializer(typeof(List<MassData>));
				serializer.Serialize(fs, massDatas);
			}
		}
	}

	private void tsbtnSave_Click(object sender, EventArgs e)
	{
		SaveFileDialog sfd = new SaveFileDialog();
		sfd.Filter = "jepg图片(*.jpg)|*.jpg";
		if (sfd.ShowDialog() == DialogResult.OK)
		{
			Bitmap catchBmp = new Bitmap(splitContainer1.Width, splitContainer1.Height);
			Graphics g = Graphics.FromImage(catchBmp);
			Point screenPoint = splitContainer1.PointToScreen(new Point(0, 0));
			g.CopyFromScreen(screenPoint, new Point(0, 0), new Size(splitContainer1.Width, splitContainer1.Height));
			catchBmp.Save(sfd.FileName);
		}
	}

	private void ThreadRefresh()
	{
		while (!stopScan)
		{
			RefreshGraph();
			Thread.Sleep(200);
		}
	}

	private void RefreshGraph()
	{
		graphSpectrum.GraphPane.AxisChange();
		try
		{
			Invoke((EventHandler)delegate
			{
				graphSpectrum.Refresh();
			});
		}
		catch
		{
		}
	}

	private void FormScan_Ncs_FormClosing(object sender, FormClosingEventArgs e)
	{
		Detector.analogReceive -= Scan_analogRecieve;
		Detector.pulseReceive -= Scan_pulseReceive;
		Detector.finishReceive -= Scan_massFinishReceive;
	}

	private void dgvMass_MouseDown(object sender, MouseEventArgs e)
	{
		if (e.Button != MouseButtons.Right)
		{
			return;
		}
		ContextMenu menu = new ContextMenu();
		menu.MenuItems.Add(Lang.Txt("FormScanNCS.Menu.Order.Text"), delegate
		{
			BindMass();
		});
		menu.MenuItems.Add(Lang.Txt("FormScanNCS.Menu.add.Text"), delegate
		{
			AddMass();
			BindMass();
		});
		menu.MenuItems.Add(Lang.Txt("FormScanNCS.Menu.Delete.Text"), delegate
		{
			if (dgvMass.SelectedRows != null && dgvMass.SelectedRows.Count > 0)
			{
				List<int> list = new List<int>();
				for (int i = 0; i < dgvMass.SelectedRows.Count; i++)
				{
					list.Add(dgvMass.SelectedRows[i].Index);
				}
				DeleteMass(list.Min(), dgvMass.SelectedRows.Count);
				BindMass();
			}
		});
		menu.Show(dgvMass, e.Location);
	}

	private void AddMass()
	{
		MassData msdata = new MassData();
		massDatas.Add(msdata);
	}

	private void DeleteMass(int startIndex, int count)
	{
		if (startIndex + count > massDatas.Count)
		{
			count = massDatas.Count - startIndex;
		}
		massDatas.RemoveRange(startIndex, count);
	}

	private void DeleteMass(int index)
	{
		massDatas.RemoveAt(index);
	}

	private void dgvMass_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
	{
		if (e.ColumnIndex < 0 || e.RowIndex < 0)
		{
			return;
		}
		string dataPropertyName = dgvMass.Columns[e.ColumnIndex].DataPropertyName;
		string text = dataPropertyName;
		if (text == "symbol")
		{
			MassData massdata = massDatas[e.RowIndex];
			FormMassSelect formMassSelect = new FormMassSelect(DataBase.Instance, massdata.symbol);
			if (formMassSelect.ShowDialog() == DialogResult.OK)
			{
				massdata.atom = formMassSelect.SelectedIsotope.atomicSymbol;
				massdata.symbol = formMassSelect.SelectedIsotope.symbol;
				massdata.mass = formMassSelect.SelectedIsotope.mass;
				massdata.start = (float)(massdata.mass - 1.0);
				massdata.end = (float)(massdata.mass + 1.0);
				massdata.bDC = (float)CalculateDC(massdata.mass, QuadMonitor.quad.ReadFreq);
				massdata.bRF = (float)CalculateRF(massdata.mass, QuadMonitor.quad.ReadFreq);
				massdata.kDC = 0f;
				massdata.kRF = 0f;
				dgvMass.InvalidateRow(e.RowIndex);
			}
		}
	}

	private void FormScan_Ncs_Leave(object sender, EventArgs e)
	{
		FormInstrumentTune.massDatas = massDatas;
	}

	private void toolStripButton1_Click(object sender, EventArgs e)
	{
		if (Detector.Instance.ExperimentState != -1)
		{
			if (Detector.Instance.ExperimentState == 4)
			{
				MessageBox.Show(Lang.Txt("ADDTune.TipsText1.Text"), Lang.Txt("AddFormIgnite.Warn"));
				return;
			}
			if (MessageBox.Show(Lang.Txt("ADDTune.TipsText2.Text"), Lang.Txt("AddFormIgnite.Warn"), MessageBoxButtons.YesNo) != DialogResult.Yes)
			{
				return;
			}
			Detector.Instance.ExperimentStateChange(Detector.Instance.ExperimentState);
		}
		if (!InitScan())
		{
			MessageBox.Show(Lang.Txt("FormScanNCS.MessageBox.ErrorSet.Text"));
			return;
		}
		EnableScan(enable: false);
		sweepIndex = 0;
		massIndex = 0;
		stopScan = false;
		Task.Factory.StartNew(ThreadRefresh);
		Task.Factory.StartNew(FindMass);
		Detector.Instance.ExperimentState = 4;
	}

	private void FindMass()
	{
		InitMasses();
		FindAr2();
		FindOtherSymbol();
		StopScan();
	}

	private void InitMass(string symbol, double mass)
	{
		int index = massDatas.FindIndex((MassData r) => Math.Abs(r.mass - mass) < 0.01);
		if (index == -1)
		{
			MassData massdata = new MassData();
			massdata.symbol = symbol;
			massdata.mass = mass;
			massdata.start = (float)(massdata.mass - 1.0);
			massdata.end = (float)(massdata.mass + 1.0);
			massdata.bDC = (float)CalculateDC(massdata.mass, QuadMonitor.quad.ReadFreq);
			massdata.bRF = (float)CalculateRF(massdata.mass, QuadMonitor.quad.ReadFreq);
			massdata.kDC = 0f;
			massdata.kRF = 0f;
			massdata.sweeps = 1;
			massDatas.Add(massdata);
		}
		else
		{
			massDatas[index].success = false;
		}
	}

	private void InitMasses()
	{
		InitMass("59Co", 58.933);
		InitMass("7Li", 7.016);
		InitMass("80Se", 79.917);
		InitMass("89Y", 88.906);
		InitMass("115In", 114.904);
		InitMass("140Ce", 139.905);
		InitMass("209Bi", 208.98);
		InitMass("238U", 238.051);
		massDatas.Sort((MassData m1, MassData m2) => m1.mass.CompareTo(m2.mass));
		Invoke((MethodInvoker)delegate
		{
			BindMass();
		});
	}

	private void FindAr2()
	{
		float oldHVP = RFManager.rfs.HVP;
		int index = massDatas.FindIndex((MassData r) => r.symbol == "80Se");
		MassData massdata = massDatas[index];
		if (Math.Abs((double)massdata.start - massdata.mass) < 5.0)
		{
			massdata.start = (float)massdata.mass - 5f;
		}
		if (Math.Abs((double)massdata.end - massdata.mass) < 5.0)
		{
			massdata.end = (float)massdata.mass + 5f;
		}
		massdata.success = false;
		deltaDC = 1.0;
		oldDCPos = double.NaN;
		while (!massdata.success && !stopScan)
		{
			if (StartScanSingle(massdata))
			{
				if (ProcessDatas(massdata))
				{
					massdata.success = true;
					break;
				}
				massdata.success = false;
			}
			else
			{
				massdata.success = false;
			}
			Invoke((MethodInvoker)delegate
			{
				dgvMass.Refresh();
			});
		}
		RFManager.rfs.HVP = oldHVP;
		if (Detector.detectorConfig.IsNewDetector)
		{
			Detector.Instance.msDetectorRF.SetHVPNew();
		}
		else
		{
			Detector.Instance.msDetectorRF.SetHVP();
		}
		Thread.Sleep(3000);
		Invoke((MethodInvoker)delegate
		{
			dgvMass.Refresh();
		});
	}

	private void FindOtherSymbol()
	{
		List<MassData> masses = massDatas.FindAll((MassData r) => r.mass > 80.0);
		foreach (MassData massdata2 in masses)
		{
			int index2 = massDatas.FindIndex((MassData r) => r.mass == massdata2.mass);
			if (!massDatas[index2 - 1].success)
			{
				break;
			}
			massdata2.kRF = (massDatas[index2 - 1].bRF + massDatas[index2 - 1].kRF) / massDatas[index2 - 1].bRF * massdata2.bRF - massdata2.bRF;
			massdata2.kDC = (massDatas[index2 - 1].bDC + massDatas[index2 - 1].kDC) / massDatas[index2 - 1].bDC * massdata2.bDC - massdata2.bDC;
			deltaDC = 1.0;
			oldDCPos = double.NaN;
			while (!massdata2.success && !stopScan)
			{
				if (StartScanSingle(massdata2))
				{
					if (ProcessDatas(massdata2))
					{
						massdata2.success = true;
						break;
					}
				}
				else
				{
					massdata2.success = false;
				}
			}
			if (stopScan)
			{
				break;
			}
			Invoke((MethodInvoker)delegate
			{
				dgvMass.Refresh();
			});
		}
		List<MassData> massdataLow = massDatas.FindAll((MassData r) => r.mass < 79.0);
		massdataLow.Sort((MassData m1, MassData m2) => m2.mass.CompareTo(m1.mass));
		foreach (MassData massdata in massdataLow)
		{
			if (massdata == null)
			{
				continue;
			}
			int index = massDatas.FindIndex((MassData r) => r.mass == massdata.mass);
			if (!massDatas[index + 1].success)
			{
				break;
			}
			massdata.kRF = (massDatas[index + 1].bRF + massDatas[index + 1].kRF) / massDatas[index + 1].bRF * massdata.bRF - massdata.bRF;
			massdata.kDC = (massDatas[index + 1].bDC + massDatas[index + 1].kDC) / massDatas[index + 1].bDC * massdata.bDC - massdata.bDC;
			deltaDC = 1.0;
			oldDCPos = double.NaN;
			while (!massdata.success && !stopScan)
			{
				if (StartScanSingle(massdata))
				{
					if (ProcessDatas(massdata))
					{
						massdata.success = true;
						break;
					}
				}
				else
				{
					massdata.success = false;
				}
			}
			Invoke((MethodInvoker)delegate
			{
				dgvMass.Refresh();
			});
		}
	}

	private bool ProcessDatas(MassData massdata)
	{
		try
		{
			List<double> spectrums = new List<double>();
			for (int i = 0; i < Detector.msDetectorPara.IntesnsityPulse.Count(); i++)
			{
				spectrums.Add(Detector.msDetectorPara.IntesnsityPulse[i] / (double)massdata.sweeps);
			}
			if (spectrums.Max() >= 10000000.0)
			{
				RFManager.rfs.HVP = RFManager.rfs.HVP - 50f;
				if (Detector.detectorConfig.IsNewDetector)
				{
					Detector.Instance.msDetectorRF.SetHVPNew();
				}
				else
				{
					Detector.Instance.msDetectorRF.SetHVP();
				}
				Thread.Sleep(3000);
			}
			int index = -1;
			if (massdata.symbol == "9Be")
			{
				double max = -1.0;
				int maxindex = 0;
				for (int j = 0; j < spectrums.Count - 1 && Detector.msDetectorPara.MassAxis[j] < 9.5; j++)
				{
					if (max < spectrums[j])
					{
						max = spectrums[j];
						maxindex = j;
					}
				}
				index = maxindex;
			}
			else
			{
				index = spectrums.FindIndex((double r) => r == spectrums.Max());
			}
			double noise = spectrums.Min();
			double width = 0.0;
			if (spectrums[index] < 3.0 * noise || spectrums[index] < 1000.0)
			{
				width = 0.0;
			}
			else
			{
				double height = spectrums[index] * 0.1;
				FindCentroid(index, height, out width, spectrums.ToArray());
			}
			if (massdata.symbol == "80Se" && spectrums[index] < 10000.0)
			{
				width = 0.0;
			}
			if (width == -1.0)
			{
				return false;
			}
			double newDC = ((!(width < 0.8)) ? 1 : ((!(width > 0.75)) ? (-1) : 0));
			if (oldDCPos != double.NaN && oldDCPos != newDC)
			{
				deltaDC /= 2.0;
			}
			oldDCPos = newDC;
			if (width < 0.75)
			{
				massdata.kDC -= (float)deltaDC;
				return false;
			}
			if (width > 0.9)
			{
				massdata.kDC += (float)deltaDC;
				return false;
			}
			if (Math.Abs(Detector.msDetectorPara.MassAxis[index] - massdata.mass) > 0.1)
			{
				massdata.kDC = (massdata.kDC + massdata.bDC) * (float)Detector.msDetectorPara.MassAxis[index] / (float)massdata.mass - massdata.bDC;
				massdata.kRF = (massdata.kRF + massdata.bRF) * (float)Detector.msDetectorPara.MassAxis[index] / (float)massdata.mass - massdata.bRF;
				return false;
			}
			return true;
		}
		catch (Exception ex)
		{
			MessageBox.Show(ex.Message);
			return false;
		}
	}

	public double FindCentroid(int idx, double height, out double width, double[] Intensity)
	{
		double center = 0.0;
		int ileft = ((idx > 0) ? (idx - 1) : idx);
		int iright = idx;
		try
		{
			while (ileft > 0 && Intensity[ileft] > height)
			{
				ileft--;
			}
			for (; iright < Intensity.Length - 1 && Intensity[iright] > height; iright++)
			{
			}
			if ((ileft == 0 && Intensity[iright] > height) || (iright == Intensity.Length - 1 && Intensity[iright] > height))
			{
				center = -1.0;
				width = 2.0;
			}
			else
			{
				double[] Mass = Detector.msDetectorPara.MassAxis.ToArray();
				double xleft = InterpolateMass(Mass[ileft], Intensity[ileft], Mass[ileft + 1], Intensity[ileft + 1], height);
				double xright = InterpolateMass(Mass[iright - 1], Intensity[iright - 1], Mass[iright], Intensity[iright], height);
				center = (xleft + xright) / 2.0;
				width = Math.Abs(xleft - xright);
			}
			return center;
		}
		catch (Exception)
		{
			width = -1.0;
			return center;
		}
	}

	private static double InterpolateMass(double x1, double y1, double x2, double y2, double y)
	{
		if (x1 == x2)
		{
			return x1;
		}
		double a = (y2 - y1) / (x2 - x1);
		double b = y1 - a * x1;
		return (y - b) / a;
	}

	private bool StartScanSingle(MassData massdata)
	{
		Invoke((MethodInvoker)delegate
		{
			InitSpectrum();
		});
		SetCalibrationFactor(massdata);
		List<double> mass = SetMassAxis(massdata);
		List<int> res = new List<int>();
		for (int i = 0; i < mass.Count; i++)
		{
			res.Add(1);
		}
		sweepIndex = 0;
		while (sweepIndex < massdata.sweeps && !stopScan)
		{
			scanEvent.Reset();
			Detector.AcquistionState = 0;
			if (sweepIndex == 0)
			{
				Detector.Instance.SetMassAxis(mass.ToArray());
			}
			Detector.TimerInit();
			Detector.Instance.SendHopDatas(mass.ToArray(), res.ToArray(), true, true);
			if (!scanEvent.WaitOne(30000))
			{
				Log.InsertLog(Lang.Txt("FormScanNCS.LogContent1.Text"), Lang.Txt("FormExperLog.Text2"), Lang.Txt("FormExperLog.Text3"), (Severity)3);
				return false;
			}
			if (Detector.AcquistionState == 2)
			{
				MessageBox.Show(Lang.Txt("FormScanNCS.TipsText1.Text"), Lang.Txt("AddFormIgnite.Warn"));
				return false;
			}
			Detector.TimerDeinit();
			if (stopScan)
			{
				return false;
			}
			sweepIndex++;
		}
		if (Detector.AcquistionState == 2)
		{
			return false;
		}
		return true;
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		this.components = new System.ComponentModel.Container();
		System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ICP_MS.Plugin.Tune.FormScan_Ncs));
		System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
		System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
		this.toolStrip1 = new System.Windows.Forms.ToolStrip();
		this.tsbtnScan = new System.Windows.Forms.ToolStripButton();
		this.tsbtnStop = new System.Windows.Forms.ToolStripButton();
		this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
		this.toolStripButton1 = new System.Windows.Forms.ToolStripButton();
		this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
		this.tsbtnImport = new System.Windows.Forms.ToolStripButton();
		this.tsbtnExport = new System.Windows.Forms.ToolStripButton();
		this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator();
		this.tsbtnSave = new System.Windows.Forms.ToolStripButton();
		this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
		this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
		this.tscbSpectrum = new System.Windows.Forms.ToolStripComboBox();
		this.splitContainer1 = new System.Windows.Forms.SplitContainer();
		this.dgvMass = new System.Windows.Forms.DataGridView();
		this.ColSymbol = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.colStart = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.colEnd = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.colChannels = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.colSweeps = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.colkRf = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.colbRF = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.colkDC = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.colbDC = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.graphSpectrum = new ZedGraph.ZedGraphControl();
		this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.dataGridViewTextBoxColumn2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.dataGridViewTextBoxColumn3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.dataGridViewTextBoxColumn4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.dataGridViewTextBoxColumn5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.dataGridViewTextBoxColumn6 = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.dataGridViewTextBoxColumn7 = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.dataGridViewTextBoxColumn8 = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.toolStrip1.SuspendLayout();
		((System.ComponentModel.ISupportInitialize)this.splitContainer1).BeginInit();
		this.splitContainer1.Panel1.SuspendLayout();
		this.splitContainer1.Panel2.SuspendLayout();
		this.splitContainer1.SuspendLayout();
		((System.ComponentModel.ISupportInitialize)this.dgvMass).BeginInit();
		base.SuspendLayout();
		this.toolStrip1.AutoSize = false;
		this.toolStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
		this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[12]
		{
			this.tsbtnScan, this.tsbtnStop, this.toolStripSeparator1, this.toolStripButton1, this.toolStripSeparator2, this.tsbtnImport, this.tsbtnExport, this.toolStripSeparator5, this.tsbtnSave, this.toolStripSeparator4,
			this.toolStripSeparator3, this.tscbSpectrum
		});
		this.toolStrip1.Location = new System.Drawing.Point(0, 0);
		this.toolStrip1.Name = "toolStrip1";
		this.toolStrip1.Size = new System.Drawing.Size(1337, 65);
		this.toolStrip1.TabIndex = 0;
		this.toolStrip1.Text = "toolStrip1";
		this.tsbtnScan.AutoSize = false;
		this.tsbtnScan.Image = ICP_MS.Plugin.Tune.Properties.Resources.Run;
		this.tsbtnScan.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
		this.tsbtnScan.ImageTransparentColor = System.Drawing.Color.Magenta;
		this.tsbtnScan.Name = "tsbtnScan";
		this.tsbtnScan.Size = new System.Drawing.Size(50, 50);
		this.tsbtnScan.Text = "扫描";
		this.tsbtnScan.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
		this.tsbtnScan.Click += new System.EventHandler(tsbtnScan_Click);
		this.tsbtnStop.AutoSize = false;
		this.tsbtnStop.Image = ICP_MS.Plugin.Tune.Properties.Resources.Stop;
		this.tsbtnStop.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
		this.tsbtnStop.ImageTransparentColor = System.Drawing.Color.Magenta;
		this.tsbtnStop.Name = "tsbtnStop";
		this.tsbtnStop.Size = new System.Drawing.Size(50, 50);
		this.tsbtnStop.Text = "终止";
		this.tsbtnStop.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
		this.tsbtnStop.Click += new System.EventHandler(tsbtnStop_Click);
		this.toolStripSeparator1.Name = "toolStripSeparator1";
		this.toolStripSeparator1.Size = new System.Drawing.Size(6, 65);
		this.toolStripButton1.Image = (System.Drawing.Image)resources.GetObject("toolStripButton1.Image");
		this.toolStripButton1.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
		this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
		this.toolStripButton1.Name = "toolStripButton1";
		this.toolStripButton1.Size = new System.Drawing.Size(73, 62);
		this.toolStripButton1.Text = "自动校正";
		this.toolStripButton1.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
		this.toolStripButton1.Click += new System.EventHandler(toolStripButton1_Click);
		this.toolStripSeparator2.Name = "toolStripSeparator2";
		this.toolStripSeparator2.Size = new System.Drawing.Size(6, 65);
		this.tsbtnImport.AutoSize = false;
		this.tsbtnImport.Image = ICP_MS.Plugin.Tune.Properties.Resources.Open;
		this.tsbtnImport.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
		this.tsbtnImport.ImageTransparentColor = System.Drawing.Color.Magenta;
		this.tsbtnImport.Name = "tsbtnImport";
		this.tsbtnImport.Size = new System.Drawing.Size(50, 50);
		this.tsbtnImport.Text = "导入";
		this.tsbtnImport.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
		this.tsbtnImport.ToolTipText = "导入扫描区间数据";
		this.tsbtnImport.Click += new System.EventHandler(tsbtnImport_Click);
		this.tsbtnExport.AutoSize = false;
		this.tsbtnExport.Image = ICP_MS.Plugin.Tune.Properties.Resources.save;
		this.tsbtnExport.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
		this.tsbtnExport.ImageTransparentColor = System.Drawing.Color.Magenta;
		this.tsbtnExport.Name = "tsbtnExport";
		this.tsbtnExport.Size = new System.Drawing.Size(50, 50);
		this.tsbtnExport.Text = "区间";
		this.tsbtnExport.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
		this.tsbtnExport.ToolTipText = "导出扫描区间数据";
		this.tsbtnExport.Click += new System.EventHandler(tsbtnExport_Click);
		this.toolStripSeparator5.Name = "toolStripSeparator5";
		this.toolStripSeparator5.Size = new System.Drawing.Size(6, 65);
		this.tsbtnSave.Image = ICP_MS.Plugin.Tune.Properties.Resources.save;
		this.tsbtnSave.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
		this.tsbtnSave.ImageTransparentColor = System.Drawing.Color.Magenta;
		this.tsbtnSave.Name = "tsbtnSave";
		this.tsbtnSave.Size = new System.Drawing.Size(43, 62);
		this.tsbtnSave.Text = "谱图";
		this.tsbtnSave.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
		this.tsbtnSave.ToolTipText = "保存谱图数据";
		this.tsbtnSave.Click += new System.EventHandler(tsbtnSave_Click);
		this.toolStripSeparator4.Name = "toolStripSeparator4";
		this.toolStripSeparator4.Size = new System.Drawing.Size(6, 65);
		this.toolStripSeparator3.Name = "toolStripSeparator3";
		this.toolStripSeparator3.Size = new System.Drawing.Size(6, 65);
		this.tscbSpectrum.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
		this.tscbSpectrum.Items.AddRange(new object[3] { "模拟计数", "PC计数", "全部谱图" });
		this.tscbSpectrum.Name = "tscbSpectrum";
		this.tscbSpectrum.Size = new System.Drawing.Size(160, 65);
		this.tscbSpectrum.SelectedIndexChanged += new System.EventHandler(tsbtnSpectrum_SelectedIndexChanged);
		this.splitContainer1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
		this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
		this.splitContainer1.Location = new System.Drawing.Point(0, 65);
		this.splitContainer1.Margin = new System.Windows.Forms.Padding(4);
		this.splitContainer1.Name = "splitContainer1";
		this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
		this.splitContainer1.Panel1.Controls.Add(this.dgvMass);
		this.splitContainer1.Panel2.Controls.Add(this.graphSpectrum);
		this.splitContainer1.Size = new System.Drawing.Size(1337, 779);
		this.splitContainer1.SplitterDistance = 296;
		this.splitContainer1.SplitterWidth = 5;
		this.splitContainer1.TabIndex = 1;
		this.dgvMass.AllowUserToAddRows = false;
		this.dgvMass.AllowUserToDeleteRows = false;
		dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
		dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
		dataGridViewCellStyle1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
		dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
		dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
		dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
		dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
		this.dgvMass.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
		this.dgvMass.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
		this.dgvMass.Columns.AddRange(this.ColSymbol, this.colStart, this.colEnd, this.colChannels, this.colSweeps, this.colkRf, this.colbRF, this.colkDC, this.colbDC);
		dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
		dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window;
		dataGridViewCellStyle2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
		dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText;
		dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
		dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
		dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
		this.dgvMass.DefaultCellStyle = dataGridViewCellStyle2;
		this.dgvMass.Dock = System.Windows.Forms.DockStyle.Fill;
		this.dgvMass.Location = new System.Drawing.Point(0, 0);
		this.dgvMass.Margin = new System.Windows.Forms.Padding(4);
		this.dgvMass.Name = "dgvMass";
		this.dgvMass.RowTemplate.Height = 23;
		this.dgvMass.Size = new System.Drawing.Size(1333, 292);
		this.dgvMass.TabIndex = 0;
		this.dgvMass.CellMouseDoubleClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(dgvMass_CellMouseDoubleClick);
		this.dgvMass.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(dgvMass_DataError);
		this.dgvMass.MouseDown += new System.Windows.Forms.MouseEventHandler(dgvMass_MouseDown);
		this.ColSymbol.DataPropertyName = "symbol";
		this.ColSymbol.HeaderText = "元素";
		this.ColSymbol.Name = "ColSymbol";
		this.ColSymbol.Width = 60;
		this.colStart.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
		this.colStart.DataPropertyName = "start";
		this.colStart.HeaderText = "起始(m/z)";
		this.colStart.Name = "colStart";
		this.colEnd.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
		this.colEnd.DataPropertyName = "end";
		this.colEnd.HeaderText = "结束(m/z)";
		this.colEnd.Name = "colEnd";
		this.colChannels.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
		this.colChannels.DataPropertyName = "channels";
		this.colChannels.HeaderText = "通道";
		this.colChannels.Name = "colChannels";
		this.colSweeps.DataPropertyName = "sweeps";
		this.colSweeps.HeaderText = "叠加";
		this.colSweeps.Name = "colSweeps";
		this.colkRf.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
		this.colkRf.DataPropertyName = "kRF";
		this.colkRf.HeaderText = "ΔRF";
		this.colkRf.Name = "colkRf";
		this.colbRF.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
		this.colbRF.DataPropertyName = "bRF";
		this.colbRF.HeaderText = "T-RF";
		this.colbRF.Name = "colbRF";
		this.colkDC.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
		this.colkDC.DataPropertyName = "kDC";
		this.colkDC.HeaderText = "ΔDC";
		this.colkDC.Name = "colkDC";
		this.colbDC.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
		this.colbDC.DataPropertyName = "bDC";
		this.colbDC.HeaderText = "T-DC";
		this.colbDC.Name = "colbDC";
		this.graphSpectrum.Dock = System.Windows.Forms.DockStyle.Fill;
		this.graphSpectrum.Location = new System.Drawing.Point(0, 0);
		this.graphSpectrum.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4);
		this.graphSpectrum.Name = "graphSpectrum";
		this.graphSpectrum.ScrollGrace = 0.0;
		this.graphSpectrum.ScrollMaxX = 0.0;
		this.graphSpectrum.ScrollMaxY = 0.0;
		this.graphSpectrum.ScrollMaxY2 = 0.0;
		this.graphSpectrum.ScrollMinX = 0.0;
		this.graphSpectrum.ScrollMinY = 0.0;
		this.graphSpectrum.ScrollMinY2 = 0.0;
		this.graphSpectrum.Size = new System.Drawing.Size(1333, 474);
		this.graphSpectrum.TabIndex = 0;
		this.dataGridViewTextBoxColumn1.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
		this.dataGridViewTextBoxColumn1.DataPropertyName = "start";
		this.dataGridViewTextBoxColumn1.HeaderText = "起始(m/z)";
		this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
		this.dataGridViewTextBoxColumn2.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
		this.dataGridViewTextBoxColumn2.DataPropertyName = "end";
		this.dataGridViewTextBoxColumn2.HeaderText = "结束(m/z)";
		this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2";
		this.dataGridViewTextBoxColumn3.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
		this.dataGridViewTextBoxColumn3.DataPropertyName = "channels";
		this.dataGridViewTextBoxColumn3.HeaderText = "Channels";
		this.dataGridViewTextBoxColumn3.Name = "dataGridViewTextBoxColumn3";
		this.dataGridViewTextBoxColumn4.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
		this.dataGridViewTextBoxColumn4.DataPropertyName = "kRF";
		this.dataGridViewTextBoxColumn4.HeaderText = "k-RF";
		this.dataGridViewTextBoxColumn4.Name = "dataGridViewTextBoxColumn4";
		this.dataGridViewTextBoxColumn5.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
		this.dataGridViewTextBoxColumn5.DataPropertyName = "bRF";
		this.dataGridViewTextBoxColumn5.HeaderText = "b-RF";
		this.dataGridViewTextBoxColumn5.Name = "dataGridViewTextBoxColumn5";
		this.dataGridViewTextBoxColumn6.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
		this.dataGridViewTextBoxColumn6.DataPropertyName = "kDC";
		this.dataGridViewTextBoxColumn6.HeaderText = "k-DC";
		this.dataGridViewTextBoxColumn6.Name = "dataGridViewTextBoxColumn6";
		this.dataGridViewTextBoxColumn7.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
		this.dataGridViewTextBoxColumn7.DataPropertyName = "bDC";
		this.dataGridViewTextBoxColumn7.HeaderText = "b-DC";
		this.dataGridViewTextBoxColumn7.Name = "dataGridViewTextBoxColumn7";
		this.dataGridViewTextBoxColumn8.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
		this.dataGridViewTextBoxColumn8.DataPropertyName = "bDC";
		this.dataGridViewTextBoxColumn8.HeaderText = "b-DC";
		this.dataGridViewTextBoxColumn8.Name = "dataGridViewTextBoxColumn8";
		base.AutoScaleDimensions = new System.Drawing.SizeF(8f, 15f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(1337, 844);
		base.Controls.Add(this.splitContainer1);
		base.Controls.Add(this.toolStrip1);
		base.Margin = new System.Windows.Forms.Padding(4);
		base.Name = "FormScan_Ncs";
		base.ShowIcon = false;
		this.Text = "临时测试";
		base.FormClosing += new System.Windows.Forms.FormClosingEventHandler(FormScan_Ncs_FormClosing);
		base.Load += new System.EventHandler(FormScan_Ncs_Load);
		base.Leave += new System.EventHandler(FormScan_Ncs_Leave);
		this.toolStrip1.ResumeLayout(false);
		this.toolStrip1.PerformLayout();
		this.splitContainer1.Panel1.ResumeLayout(false);
		this.splitContainer1.Panel2.ResumeLayout(false);
		((System.ComponentModel.ISupportInitialize)this.splitContainer1).EndInit();
		this.splitContainer1.ResumeLayout(false);
		((System.ComponentModel.ISupportInitialize)this.dgvMass).EndInit();
		base.ResumeLayout(false);
	}
}
